package com.sanjiahantang.youjiarole.module.article.views.impl;

import android.content.Intent;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.module.article.presenters.ArticlePresenter;
import com.sanjiahantang.youjiarole.module.article.views.ArticleView;
import com.sanjiahantang.youjiarole.module.common.beans.HelpBean;
import com.sanjiahantang.youjiarole.module.common.views.impl.SearchActivity;
import com.sanjiahantang.youjiarole.module.common.views.impl.WebActivity;

import java.util.List;

/**
 * Created by zy on 2017/10/30.
 */

public class ArticleTypeListActivity extends BaseMvpActivity<ArticleView,ArticlePresenter>
        implements ArticleView, View.OnClickListener ,BaseView.OnLoadListener{


    private ListView listView;
    private QuickAdapter<HelpBean.Item> listAdapter;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public ArticlePresenter initPresenter() {
        return new ArticlePresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_article_list);
        findViewById(R.id.iv_back).setOnClickListener(this);
        findViewById(R.id.cetSearch).setOnClickListener(this);

        listView = (ListView) findViewById(R.id.listView);
        listView.setDivider(null);


        listAdapter = new QuickAdapter<HelpBean.Item>($this, R.layout.item_text) {
            @Override
            protected void convert(BaseAdapterHelper helper, final HelpBean.Item item) {
                helper.setText(R.id.text1,item.getArTypeName());
                helper.getView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, ArticleListActivity.class);
                        intent.putExtra(KEY_ID,item.getArTypeId());
                        intent.putExtra(KEY_TYPE,WEB_TYPE_MATCH_CENTER);
                        context.startActivity(intent);
                    }
                });
            }
        };

        listView.setAdapter(listAdapter);
    }

    @Override
    public void initData() {
        presenter.searchArTrainInfoType($this,null,this,1);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.cetSearch:
                Intent intent = new Intent($this, SearchActivity.class);
                intent.putExtra(KEY_TYPE,SEARCH_TYPE_ARTICLE_TYPE);
                startActivity(intent);
                break;
        }
    }


    @Override
    public void onLoad(Object content) {
        listAdapter.clear();
        listAdapter.addAll((List<HelpBean.Item>) content);
    }
}
